package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.pojo.BaseResp;
import com.qf.pojo.Shop;
import com.qf.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 高圆圆
 * @date 2023/2/7 16:18
 *
 */
@RestController //@Controller+@ResponseBody组合注解
@RequestMapping("/layUi_shop")
public class ShopLayUiController {

    @Autowired
    private ShopService shopService ;

    @GetMapping("/findAll")
    public BaseResp findAllShop(@RequestParam("page") String page,
                                @RequestParam("limit") String limit ){
        System.out.println(page+"---"+limit);
        int pageNum = Integer.parseInt(page) ;
        int pageSize= Integer.parseInt(limit) ;
        PageInfo pageInfo = shopService.getAllShops(pageNum, pageSize);
        //创建BaseResp对象
        BaseResp resp = new BaseResp() ;
        resp.setCode(0) ;
        resp.setMsg("获取到了");
        resp.setCount(pageInfo.getTotal());
        resp.setData(pageInfo.getList());  //[{"id":1,"pname":"xx",},{},{}]
        return  resp  ;
    }


    @PostMapping("/update")
    public BaseResp editShop(@RequestBody  Shop shop){
        System.out.println(shop);
        int count = shopService.updateShop(shop);
        if(count>0){
            return  new BaseResp(0,"修改成功",null,null) ;
        }
        return null;
    }
}
